package cn.itcalvin.sncoal.cth.controller;

import cn.itcalvin.sncoal.cth.aspect.LogAnnotation;
import cn.itcalvin.sncoal.cth.aspect.NotAuthAnnotation;
import cn.itcalvin.sncoal.cth.aspect.RoleAnnotation;
import cn.itcalvin.sncoal.cth.component.ConfigCacheUtils;
import cn.itcalvin.sncoal.cth.domain.ConfigSystem;
import cn.itcalvin.sncoal.cth.domain.ConfigSystemZb;
import cn.itcalvin.sncoal.cth.domain.ConfigSystemZbDetails;
import cn.itcalvin.sncoal.cth.domain.ConfigSystemZbDetailsExt;
import cn.itcalvin.sncoal.cth.pojo.req.config.ReqConfigSystemZbDetailsModify;
import cn.itcalvin.sncoal.cth.pojo.response.config.RespConfigZb;
import cn.itcalvin.sncoal.cth.pojo.response.config.RespConfigZbAndDetails;
import cn.itcalvin.sncoal.cth.service.ConfigSystemService;
import cn.itcalvin.sncoal.cth.utils.JwtUtil;
import cn.itcalvin.vo.Message;
import cn.itcalvin.vo.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.val;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "考核指标维护")
@RestController
@RequestMapping("/api/configZb")
public class ConfigZbController {

    @Resource
    private ConfigSystemService configSystemService;

    @PostMapping("/listSystem")
    @LogAnnotation(value = "获取考核的系统")
    @ApiOperation(value = "获取考核的系统")
    @RoleAnnotation(value = "4")
    public Message<List<ConfigSystem>> listSystem() {
        return MessageUtil.success(ConfigCacheUtils.getInstance().getAllSystemList());
    }

    @PostMapping("/listSystemZbDetails")
    @LogAnnotation(value = "获取考核的系统的指标")
    @ApiOperation(value = "获取考核的系统的指标")
    @RoleAnnotation(value = "4")
    public Message<List<RespConfigZb>> listSystemZbDetails(@RequestParam(value = "systemId") Long systemId) {
        final val userInfo = JwtUtil.getUserInfo();
        return MessageUtil.success(ConfigCacheUtils.getInstance().getZbDetailsBySystemId(systemId,userInfo.getBelongId()));
    }


    @PostMapping("/modifyZbDetailsFunction")
    @LogAnnotation(value = "修改考核指标明细溯源方法")
    @ApiOperation(value = "修改考核指标明细溯源方法")
    @RoleAnnotation(value = "4")
    public Message modifyZbDetailsFunction(@RequestBody @Valid ReqConfigSystemZbDetailsModify reqConfigSystemZbDetailsModify){
        return MessageUtil.success(configSystemService.modifyZbDetailsFunction(reqConfigSystemZbDetailsModify));
    }

}
